import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/utils/x_load_image.dart';

import 'onnx_talk_bar_tools_view.dart';

///
/// 发送按钮
///
class OnnxSendButtonView extends StatelessWidget {
  final ValueNotifier<SendButtonState> sendButtonStateNotifier;
  final VoidCallback? onSendMessage;

  const OnnxSendButtonView({
    super.key,
    required this.sendButtonStateNotifier,
    this.onSendMessage,
  });

  @override
  Widget build(BuildContext context) {
    return ValueListenableBuilder<SendButtonState>(
      valueListenable: sendButtonStateNotifier,
      builder: (context, state, child) {
        return GestureDetector(
          onTap: state != SendButtonState.disabled ? onSendMessage : null,
          child: Container(
            width: 36,
            height: 36,
            margin: const EdgeInsets.only(bottom: 2),
            child: _buildButtonIcon(state),
          ),
        );
      },
    );
  }

  Widget _buildButtonIcon(SendButtonState state) {
    switch (state) {
      case SendButtonState.disabled:
        return XAssetsImage.load('icon_agent_send_disabled');
      case SendButtonState.enabled:
        return XAssetsImage.load('icon_agent_send');
      case SendButtonState.loading:
        return XAssetsImage.load('icon_agent_stop');
    }
  }
}
